<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/2/26
  Time: 12:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>后台-登录</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script type="text/javascript" src="layui/layui.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <style>
        #login {
            position: relative;
            top: 50%;
            left: 50%;
            transform: translateX(-50%)translateY(-50%);
            text-align: center;
            width: 400px;
            height: 250px;
            border: 1px solid #ccc;
            padding: 20px 30px;
            border-radius: 10px;
        }

        #login .layui-form-item {
            width: 300px;
            margin: 30px 70px;
        }
    </style>
</head>
<body>
<div id="login">
    <h2>登录</h2>
    <hr>
    <p class="login_error" style="text-align: center"></p>
    <div class="layui-form-item">
        <div class="layui-input-group">
            <div class="layui-input-split layui-input-prefix">
                用户名
            </div>
            <input type="text" placeholder="请输入用户名" id="username" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-group">
            <div class="layui-input-split layui-input-prefix">
                密&nbsp;&nbsp;&nbsp;码
            </div>
            <input type="password" placeholder="请输入密码" id="password" class="layui-input">
        </div>
    </div>
    <button type="submit" class="layui-btn" id="submit" lay-submit lay-filter="demo1">立即提交</button>
</div>
</body>
</html>

<script>
    $("#submit").click(function () {
        const  login_error = $(".login_error");
        const username = $("#username").val();
        const password = $("#password").val();
        $.ajax({
            type: "POST",
            url: "/patMall/user/adminLogin",
            data:{
                username:username,
                userPwd:password
            },
            success:function (res){
                console.log(res)
                if (res.msg == "success"){
                    localStorage.setItem("adminJson",JSON.stringify(res.data));
                    window.location.href = "manage.jsp";
                }else if (res.msg == "fail"){
                    login_error.text("账户错误");
                }else if (res.msg == "error"){
                    login_error.text("密码错误");
                }else if (res.msg == "cancel"){
                    login_error.text("账户已注销")
                }
            },
            error:function (){
                alert("error");
            }
        })
    });
</script>
